﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string EmailText = webBrowser1.Document.Body.InnerHtml;
            string TelText= webBrowser1.Document.Body.InnerHtml;
            MatchCollection Emailmatches = Regex.Matches(EmailText, "[\\w]+(\\.[\\w]+)*@[\\w]+(\\.[\\w])+");
            MatchCollection Telmatches = Regex.Matches(TelText, "/\\d{3}-\\d{8}|\\d{4}-\\d{7}|^1(3[0-9]|4[57]|5[0-35-9]|7[0678]|8[0-9])\\d{8}$/");
            string text = "获取到的邮箱有:\n";
            foreach (Match match in Emailmatches)
            {
                text += match;
                text += "\n";
            }
            text += "获取到的电话有:\n";
            foreach (Match match in Telmatches) {
                {
                    text += match;
                    text += '\n';
                } }

            try
            {
                if(EmailText!=null && TelText!=null)
                {
                    MessageBox.Show(text);
                }
                else
                {
                    throw new Exception("没有找到任何邮箱或者电话");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }
    }
}
